<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8">
        <title>
            X-admin v1.0
        </title>
        <meta name="renderer" content="webkit">
        <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
        <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
        <meta name="apple-mobile-web-app-status-bar-style" content="black">
        <meta name="apple-mobile-web-app-capable" content="yes">
        <meta name="format-detection" content="telephone=no">
        <link rel="stylesheet" href="./css/x-admin.css" media="all">
    </head>
    <body>
        <div class="x-nav">
            <span class="layui-breadcrumb">
              <a><cite>首页</cite></a>
              <a><cite>会员管理</cite></a>
              <a><cite>会员列表</cite></a>
            </span>
            <a class="layui-btn layui-btn-small" style="line-height:1.6em;margin-top:3px;float:right"  href="javascript:location.replace(location.href);" title="刷新"><i class="layui-icon" style="line-height:30px">ဂ</i></a>
        </div>
        <div class="x-body">
            <form class="layui-form x-center" action="" style="width:800px">
                <div class="layui-form-pane" style="margin-top: 15px;">
                  <div class="layui-form-item">

                    <div class="layui-input-inline">
                    </div>
                    <div class="layui-input-inline" style="width:80px">
                    </div>
                  </div>
                </div> 
            </form>
            <xblock><span id="pageInfo" class="x-right" style="line-height:40px"></span></xblock>
            <table class="layui-table">
                <thead>
                    <tr>
                        <th>
                            手机号码
                        </th>
                        <th>
                            注册来源
                        </th>
                        <th>
                            注册类型
                        </th>
                        <th>
                            邀请人ID
                        </th>
                        <th>
                            注册时间
                        </th>
                        <th>
                            设备号
                        </th>

                        <th>
                            设备号类型
                        </th>
                        <th>
                            操作系统
                        </th>
                        <th>
                            平台
                        </th>
                        <th>
                            版本
                        </th>

                    </tr>
                </thead>
                <tbody id="userDiv">

                </tbody>
            </table>

            <div><button onclick="first();">首页</button>&nbsp;&nbsp;<button onclick="pre();">上一页</button>&nbsp;&nbsp;<button onclick="next();">下一页</button>&nbsp;&nbsp;<button onclick="last();">尾页</button></div>
        </div>
        <script src="/js/jquery.min.js" charset="utf-8"></script>
        <script src="/lib/layui/layui.js" charset="utf-8"></script>
        <script src="/js/x-layui.js" charset="utf-8"></script>
        <script>

            var currentPage = 1;
            var totalNum = 1;

            $(document).ready(function () {
                loadUsers();
            });

            function first() {
                currentPage = 1;
                loadUsers();
            }

            function last() {
                currentPage = totalNum;
                loadUsers();
            }

            function next() {
                if (currentPage >= totalNum) {
                    return;
                }
                currentPage ++;
                loadUsers();
            }

            function pre() {
                if (currentPage <= 1) {
                    return;
                }

                currentPage --;
                loadUsers();
            }
            function loadUsers() {
                $.ajax({
                    url: '/loadUsers',
                    type: 'GET', //GET
                    async: true,    //或false,是否异步
                    data: {
                        currentPage : currentPage
                    },
                    timeout: 10000,    //超时时间
                    dataType: 'json',    //返回的数据格式：json/xml/html/script/jsonp/text
                    success: function (ajaxData, textStatus, jqXHR) {
                        if (!ajaxData.success) {
                            alert(ajaxData.message);
                            layer.alert(ajaxData.message, {icon: 6},function () {});
                            return;
                        }

                        let msg = '';
                        let pageData = ajaxData.data;
                        let resutls = pageData.data;
                        for (let i=0; i<resutls.length;i++) {
                            msg += '<tr>';
                          msg += '                     <th>\n' +
                              '                            '+resutls[i].phone +'\n' +
                              '                        </th>\n' +
                              '                        <th>\n' +
                              '                            '+resutls[i].registSource+'\n' +
                              '                        </th>\n' +
                              '                        <th>\n' +
                              '                            '+resutls[i].registType+'\n' +
                              '                        </th>\n' +
                              '                        <th>\n' +
                              '                            '+resutls[i].inviterUserId+'\n' +
                              '                        </th>\n' +
                              '                        <th>\n' +
                              '                            '+resutls[i].registDate+'\n' +
                              '                        </th>\n' +
                              '                        <th>\n' +
                              '                            '+resutls[i].deviceNum+'\n' +
                              '                        </th>\n' +
                              '\n' +
                              '                        <th>\n' +
                              '                            '+resutls[i].deviceModle+'\n' +
                              '                        </th>\n' +
                              '                        <th>\n' +
                              '                            '+resutls[i].osVersion+'\n' +
                              '                        </th>\n' +
                              '                        <th>\n' +
                              '                            '+resutls[i].platform+'\n' +
                              '                        </th>\n' +
                              '                        <th>\n' +
                              '                            '+resutls[i].appVersion+'\n' +
                              '                        </th>';
                            msg += '</tr>';
                        }

                        totalNum = pageData.totalPage;
                        $('#userDiv').html(msg);
                        $('#pageInfo').html('总页数：' + pageData.currentPage + '/' + pageData.totalPage);
                    }
                });
            }

            /*用户-删除*/
            function member_del(obj,id){
                layer.confirm('确认要删除吗？',function(index){
                    //发异步删除数据
                    $(obj).parents("tr").remove();
                    layer.msg('已删除!',{icon:1,time:1000});
                });
            }
        </script>

    </body>
</html>